﻿using Lis.DTO;
using Lis.IBLL;
using Lis.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace Lis.WebApp.Controllers
{
    public class AppointmentController : ApiController
    {
        public IAppointmentService AppointmentService { get; set; }

        #region 01，图书预约+ServiceResult<string> HoldBook(string value, string value1)
        /// <summary>
        /// 图书预约
        /// </summary>
        /// <param name="value">读者卡号</param>
        /// <param name="value1">馆藏号</param>
        /// <returns></returns>
        [HttpGet]
        public ServiceResult<string> HoldBook(string value, string value1)
        {
            try
            {
                var holdBookDto = new BorrowBookDto()
                {
                    UserName = value,
                    BarCode = value1
                };
                return AppointmentService.HoldBook(holdBookDto);
            }
            catch (Exception)
            {
                return new ServiceResult<string>()
                {
                    Success = false,
                    Message = "网络异常，请稍后再试",
                    Code = "10010"
                };
            }
        } 
        #endregion

        #region 02，(取消)图书预约+ServiceResult<string> CancelHoldBook(string value, string value1)
        /// <summary>
        /// (取消)图书预约
        /// </summary>
        /// <param name="value">读者卡号</param>
        /// <param name="value1">馆藏号</param>
        /// <returns></returns>
        [HttpGet]
        public ServiceResult<string> CancelHoldBook(string value, string value1)
        {
            try
            {
                var holdBookDto = new BorrowBookDto()
                {
                    UserName = value,
                    BarCode = value1
                };
                return AppointmentService.CancelHoldBook(holdBookDto);
            }
            catch (Exception)
            {
                return new ServiceResult<string>()
                {
                    Success = false,
                    Message = "网络异常，请稍微再试",
                    Code = "10010"
                };
            }
        } 
        #endregion
    }
}
